package com.ldn.dao.service;

import com.mybatisflex.core.logicdelete.LogicDeleteManager;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.service.IService;
import com.ldn.dao.entities.BasicEntities;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author 李大牛家的牛 (scafel@163.com)
 * @createDate 2024/7/11 - 14:44
 * @description ...
 **/
public interface BasicService<T extends BasicEntities> extends IService<T> {

    default T getOneByCode(String code) {
        QueryWrapper query = QueryWrapper.create();
        query.eq("code", code);
        return getMapper().selectOneByQuery(query);
    }

    default T getOneById(Serializable id) {
        try{
            LogicDeleteManager.skipLogicDelete();
            QueryWrapper query =QueryWrapper.create();
            query.eq("id", id);
            return getMapper().selectOneByQuery(query);
        }finally {
            LogicDeleteManager.restoreLogicDelete();
        }
    }

    default List<T> getStatusList() {
        QueryWrapper query = QueryWrapper.create();
        query.eq("status", 1);
        return getMapper().selectListByQuery(query);
    }

    default List<T> listLogicByIds(Collection<? extends Serializable> ids){
        try{
            LogicDeleteManager.skipLogicDelete();
            QueryWrapper query =QueryWrapper.create();
            query.in("id", ids);
            return getMapper().selectListByQuery(query);
        }finally {
            LogicDeleteManager.restoreLogicDelete();
        }
    }

    boolean saveEntity(T entity);
    boolean saveBatchEntity(List<T> entities);
    boolean updateBatchEntity(List<T> entities);
    boolean updateEntity(T entity);
    boolean deleteEntity(T entity);
    boolean deleteBatchEntity(List<? extends Serializable> ids);
    boolean protectedEntity(T entity);
    boolean hotEntity(T entity);
    boolean statusEntity(T entity);
    Page<T> pageEntity(Integer page);
    Page<T> pageEntity(Integer page, Integer size);
    Page<T> pageStatusEntity(Integer page);
    Page<T> pageStatusEntity(Integer page, Integer size);
    List<T> listEntity();
    List<T> listStatusEntity();
    List<T> listEntity(Integer page);
    List<T> listStatusEntity(Integer page);

    List<T> getListByTimeForMember(Serializable memberId, long startTime, long endTime);
}
